package com.xydtech.ecard.product.controller;


import com.xydtech.common.enums.ResultStatus;
import com.xydtech.common.model.ResponseModel;
import com.xydtech.common.utils.StringUtils;
import com.xydtech.ecard.ecard.controller.EcardApiBaseController;
import com.xydtech.ecard.product.domain.EcardApiPrdBrowseList;
import com.xydtech.ecard.product.service.IEcardPrdBrowseListService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 电子名片产品浏览记录Controller
 *
 * @author busiplat
 * @date 2021-09-14
 */
@Controller
@Api(tags = "电子名片-电子名片-产品浏览记录")
@RequestMapping("/ecardSaasApi/product/browse")
public class EcardPrdBrowseListController extends EcardApiBaseController {
    @Autowired
    private IEcardPrdBrowseListService browseListService;

    /**
     * 电子名片-电子名片-新增电子名片产品浏览记录
     * @param custmanagerRegistId
     * @param prdId
     * @return
     */
    @ApiOperation(value = "电子名片-电子名片-新增电子名片产品浏览记录", notes = "电子名片-电子名片-新增电子名片产品浏览记录")
    @ApiImplicitParams(
            {@ApiImplicitParam(name = "custmanagerRegistId", value = "电子名片员工微信ID", dataType = "String", dataTypeClass = String.class, paramType = "query", required = true),
                    @ApiImplicitParam(name = "prdId", value = "产品ID", dataType = "String", dataTypeClass = String.class, paramType = "query", required = true)}
    )
    @ApiResponses({@ApiResponse(code = 0, message = "OK", response = ResponseModel.class)})
    @PostMapping("/addEcardPrdBrowseList")
    @ResponseBody
    public ResponseModel addEcardPrdBrowseList(String custmanagerRegistId, String prdId) {
        if (StringUtils.isEmpty(custmanagerRegistId) || StringUtils.isEmpty(prdId)) {
            return ResponseModel.error(ResultStatus.PARAMETER_ERROR);
        }

        //获取当前登录人信息
        String currentUserId = getCurrentUserId();
        if (custmanagerRegistId.equals(currentUserId)) {
            return ResponseModel.ok("自己访问自己的名片产品不做记录！");
        }
        EcardApiPrdBrowseList ecardApiPrdBrowseList = new EcardApiPrdBrowseList();
        //访问的产品的ID
        ecardApiPrdBrowseList.setPrdId(prdId);
        //当前用户的微信注册ID
        ecardApiPrdBrowseList.setRegistId(currentUserId);
        //产品对应的客户经理的微信注册ID
        ecardApiPrdBrowseList.setCustmanagerRegistId(custmanagerRegistId);

        int saveCount = browseListService.insertEcardPrdBrowseList(ecardApiPrdBrowseList);
        return saveCount > 0 ? ResponseModel.ok() : ResponseModel.error("插入电子名片产品访问记录失败！");
    }
}
